<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/include.inc.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/views/layout/miiteen/base.ref.jsp" %>
</head>
<body>
<div class="mainpage edit">
    <!--顶部菜单-->
    <div class="page-topmenu">
        <div class="btn-panel">
            <el-button type="primary" size="small" icon="el-icon-plus" @click="add">新增</el-button>
        </div>
        <div class="btn-panel">
            <el-button type="danger" size="small" icon="el-icon-delete" @click="del">删除</el-button>
        </div>
    </div>
    <el-container>
        <el-aside width="200px">
            <el-card shadow="never">
                <el-tree node-key="id" :data="treedata" :props="treeprop" ref="tree" :highlight-current="true"
                         :default-expand-all="true" :expand-on-click-node="false"
                         @node-click="treeClick"></el-tree>
            </el-card>
        </el-aside>
        <el-main>    <!--编辑表单-->
            <el-form :ref="formid" :model="form" :rules="rules" size="small" :label-width="labelwidth"
                     :label-position="labelposition"
                     class="one-col" :validate-on-rule-change="false">

                <!--视业务进行更改-begin-->
                <el-form-item label="岗位编码" prop="postCode">
                    <el-input v-model="form.postCode" placeholder="岗位编码"></el-input>
                </el-form-item>
                <el-form-item label="岗位名称" prop="postName">
                    <el-input v-model="form.postName" placeholder="岗位名称"></el-input>
                </el-form-item>
                <el-form-item label="显示顺序" prop="showOrder">
                    <el-input v-model="form.showOrder" placeholder="显示顺序"></el-input>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" placeholder="备注"></el-input>
                </el-form-item>
                <el-form-item label="">
                    <el-button type="primary" size="small" @click="save">保存</el-button>
                </el-form-item>

                <!--视业务进行更改-end-->

            </el-form>
        </el-main>
    </el-container>
</div>
<script>
    //初始化数据，必须放置在列表页面封装部分前
    function initVueOption(obj) {
        obj.data.labelwidth = "100px";
        //设置控制器
        obj.data.controller = "${ctx}/post/postinfo";
        //设置表单数据
        obj.data.treeprop = {
            children: 'children',
            label: 'postName'
        }
        obj.data.treedata = [];
        obj.data.form = {};
        //设置校验规则，没有则删掉
        obj.data.rules = {
            postCode: [{required: true, message: '请输入岗位编码', trigger: 'change'}],
            postName: [{required: true, message: '请输入岗位名称', trigger: 'change'}]
        }

        //新增
        obj.methods.add = function () {
            if (this.$refs.tree.getCurrentKey() == null) {
                this.form = {
                    id: "-1",
                    parentId: 0
                }
            } else {
                this.form = {
                    id: "-1",
                    parentId: this.$refs.tree.getCurrentKey()
                }
            }
        }

        //保存
        obj.methods.save = function () {
            form.edit.save(this, this.formid, this.form, this.controller + "/save");
            loadtree();
        }

        //删除部门
        obj.methods.del = function () {
            var id = this.form.id;
            if (id == null) {
                window.parent.mtMsg.warnbox("请选择要删除的岗位");
                return;
            }

            window.parent.mtMsg.confirm("确定要删除岗位\"" + this.form.postName + "\"吗?", function () {
                miiteen.ajax.get(Page.controller + "/del?ids=" + Page.form.id, function (response) {
                    var result = response.data;
                    if (result.state > 0) {
                        loadtree();
                        Page.form = {};
                        window.parent.mtMsg.success(result.message);
                    } else {
                        window.parent.mtMsg.warnbox(result.message);
                    }
                }, function (x) {
                    console.log(x)
                })
            })
        }

        obj.methods.treeClick = function (data) {
            Page.form = data;
        }

        obj.mounted = function () {
            this.$nextTick(function () {
                //页面渲染完执行的操作，加载Tree
                loadtree();
            })
        }
    }

    function loadtree() {
        miiteen.ajax.get(Page.controller + "/search", function (response) {
            var result = response.data;
            Page.treedata = AlgorithmsUtils.simpleToTree(result.data, "id", "parentId");
        })
    }
</script>
<!--编辑页面封装部分-->
<%@include file="/WEB-INF/views/layout/miiteen/page.edit.ref.jsp" %>
</body>
</html>